<template>
  <div class="alarmConfiguration zy-content">
    <search :columns="searchData" @getSearch="getSearch(arguments)"></search>
    <div class="list-layout mt16">
      <div class="btns clear">
        <span class="title">{{ $t("common.listInformation") }}</span>
        <Button @click="exportTemplateClick">{{
          $t("common.batchExport")
        }}</Button>
        <!-- <Button @click="getTableColumns(columns)">
          {{ handleContextMenuStatus ? $t("显示操作栏") : $t("隐藏操作栏") }}
        </Button> -->
      </div>
      <div class="tableContent">
        <Table
          class="resizable-table"
          border
          @on-column-width-resize="onColumnWidthResize"
          :columns="columnsList"
          ellipsis
          ref="selection"
          stripe
          :data="dataArr"
        >
        </Table>
      </div>
      <div class="pageWrap mt16">
        <pageLeftTitle :total="total" :selected="delIds.length" />
        <Page
          :total="total"
          :page-size="pageSize"
          :page-size-opts="pageSizeOption"
          :current="pageNum"
          @on-change="changePageNum"
          @on-page-size-change="changePageSize"
          show-sizer
          show-total
        />
      </div>
    </div>
  </div>
</template>

<script>
import search from "@/components/curd/searchList.vue";
import fileDownload from "js-file-download";
import toggleTableOperation from "@/mixins/toggleTableOperation";
export default {
  name: "benchmarkActualAnalysis",
  components: { search },
  mixins: [toggleTableOperation],
  data() {
    return {
      loading: false,
      searchParams: {},
      pageNum: 1,
      pageSize: 10,
      total: 0,
      delIds: [],
      searchData: [
        {
          title: "模具名称",
          key: "moldName",
        },
        {
          title: "模具编号",
          key: "moldCode",
        },
        {
          title: "任务生成时间",
          key: "time",
          format: "yyyy-MM-dd HH:mm:ss",
          type: "datetimerange",
        },
        {
          title: "点检时间",
          key: "time1",
          format: "yyyy-MM-dd HH:mm:ss",
          type: "datetimerange",
        },
        {
          title: "点检人",
          key: "operName",
          dicUrl: "/basic/user/searchUser",
          type: "search",
          queryName: "key",
          resultParams: "res.data",
          params: {
            label: "realname",
            value: "realname",
          },
        },
      ],
      columns: [
        {
          title: "点检单号",
          key: "id",
          minWidth: 130,
          align: "center",
          resizable: true,
        },

        {
          title: "模具名称",
          key: "moldName",
          minWidth: 130,
          align: "center",
          resizable: true,
        },
        {
          title: "模具编号",
          key: "moldCode",
          minWidth: 130,
          align: "center",
          resizable: true,
        },
        {
          title: "点检计划",
          key: "planName",
          minWidth: 150,
          align: "center",
          resizable: true,
        },
        {
          title: "点检人",
          key: "operName",
          minWidth: 150,
          align: "center",
          resizable: true,
        },
        {
          title: "任务生成时间",
          key: "createTime",
          minWidth: 150,
          align: "center",
          resizable: true,
        },
        {
          title: "开始检点时间",
          key: "beginTime",
          minWidth: 150,
          align: "center",
          resizable: true,
        },
        {
          title: "结束点检时间",
          key: "endTime",
          minWidth: 150,
          align: "center",
          resizable: true,
        },
        {
          title: "点检总时长(min)",
          key: "checkTime",
          minWidth: 150,
          align: "center",
          resizable: true,
        },
      ],
      dataArr: [],
      pageSizeOption: [10, 20, 30, 40],
    };
  },
  mounted() {
    this.getTableColumnsWidth(this.columns);
    this.searchList();
  },
  methods: {
    getSearch(arg) {
      this.searchParams = JSON.parse(JSON.stringify(arg[0]));
      if (this.searchParams.time && this.searchParams.time.length > 0) {
        this.searchParams.createTimeB = this.searchParams.time[0];
        this.searchParams.createTimeE = this.searchParams.time[1];
        delete this.searchParams.time;
      }
      if (this.searchParams.time1 && this.searchParams.time1.length > 0) {
        this.searchParams.beginTimeB = this.searchParams.time1[0];
        this.searchParams.beginTimeE = this.searchParams.time1[1];
        delete this.searchParams.time1;
      }
      this.pageNum=1;
      this.searchList();
    },
    reset() {
      this.searchParams = {};
      this.changeNum();
    },
    //分页
    changeNum() {
      this.pageNum = 1;
      this.searchList();
    },
    changePageSize(pageSize) {
      this.pageSize = pageSize;
      this.searchList();
    },

    changePageNum(val) {
      this.pageNum = val;
      this.searchList();
    },
    //查询列表
    searchList() {
      let params = {
        pageNum: this.pageNum,
        pageSize: this.pageSize,
        ...this.searchParams,
      };
      this.axios({
        method: "post",
        url: "/dms/moldSpotCheckTask/querySpotCheckTaskList",
        data: params,
      }).then((res) => {
        if (res.code === 200) {
          this.dataArr = res.data.records;
          this.total = res.data.total;
        } else {
          this.$Message.warning({
            content: res.msg,
            duration: 6,
            closable: true,
          });
        }
      });
    },
    //导出
    exportTemplateClick() {
      let params = {
        delIds: this.delIds,
      };
      for (let key in this.searchParams) {
        if (this.searchParams[key]) {
          this.$set(params, key, this.searchParams[key]);
        }
      }
      const filName = "模具维修报表";
      this.axios({
        url: "/dms/moldSpotCheckTask/exportSpotCheckTaskList",
        method: "post",
        responseType: "blob",
        data: params,
      }).then((res) => {
        fileDownload(res, filName + ".xls");
      });
    },
  },
};
</script>

<style scoped lang="scss">
.ivu-input-number {
  width: -webkit-fill-available;
}

.row_click {
  cursor: pointer;
  color: rgb(50, 113, 240) !important;
}
</style>
